package com.escape.auth.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.escape.auth.common.enums.IsDeletedEnum;
import com.escape.auth.domain.convert.AuthRoleConverter;
import com.escape.auth.domain.entity.AuthRoleBO;
import com.escape.auth.domain.service.AuthRoleDomainService;
import com.escape.auth.infra.basic.entity.AuthRole;
import com.escape.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: escape_zebra
 * @CreateTime: 2025-01-09  17:12
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    private AuthRoleService authRoleService;

    /**
     * 新增角色
     */
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.add.bo:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleConverter.INSTANCE.convertBoToEntity(authRoleBO);

        authRole.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());

        Integer count = this.authRoleService.insert(authRole);

        return count > 0;
    }

    /**
     * 更新角色
     */
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.update.bo:{}", JSON.toJSONString(authRoleBO));
        }

        AuthRole authRole = AuthRoleConverter.INSTANCE.convertBoToEntity(authRoleBO);
        Integer count = this.authRoleService.update(authRole);
        return count > 0;
    }

    /**
     * 删除角色
     */
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        if (log.isInfoEnabled()) {
            log.info("AuthRoleDomainServiceImpl.delete.bo:{}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = new AuthRole();
        authRole.setId(authRoleBO.getId());
        authRole.setIsDeleted(IsDeletedEnum.DELETED.getCode());

        Integer count = this.authRoleService.update(authRole);

        return count > 0;
    }
}
